/*-------------------<-- Start of Description-->---------------------\
| Generate a readme.doc file under the directory you specified; |
| Note: the files must include the header using the format exactly |
| like this file; |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|-----------<-- Start of Files or Arguements Needed-->---------------|
| Parameters: |
| directory - the complete path to the directory you want to |
| create your readme.doc file for; |
| stopsign - the end of the file header; |
| outdata - output dataset; |
| fextension - the type of files you want to create readme for; |
|-----------------<-- End of Arguements Needed-->--------------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %GenReadMe(directory=T:\TACHY\BIOSTAT\Duo\Projects\ |
| ACED-RID\DBget\ProgComp,outdata=dircnts); |
| Usage: %GenReadMe(directory=,stopsign='-----/', outdata=, |
| fextension='.sas'); |
\-------------------<-- End of Files Created-->---------------------*/
%macro GenReadMe(directory=,stopsign='-----*/', outdata=, fextension='.sas', type='xls');
/*---------------------------------------------\
| Copy Right: Duo Zhou; |
| Created: 10-30-2001 10:46pm; |
| Purpose: Generate Readme Files under the |
| directory; |
\---------------------------------------------*/
/* The file assumes you have your file description listed in the file header */
/* the stopsign is the end of the file header. */
%local _tmplast_ directory stopsign outdata fextension type; %let _tmplast_=&syslast;
%let directory=%sysfunc(dequote(&directory));
%let fextension="%trim(%left(%upcase(%sysfunc(dequote(&fextension)))))";
%let stopsign="%sysfunc(dequote(&stopsign))";
%let olddir=&directory;
%let output=&outdata;
%if (%length(%trim(%left(&directory))) >1) %then %do;
%if (%quote(%substr(&directory, %length(&directory), 1)) ne %quote(\)) %then %do;
%let directory=&directory.\;
%end;
%let ddir=%substr(&directory, 1, %eval(%length(&directory)-1));
%end;
%let dirrc=%sysfunc(filename(dirrf,&directory));
%let psid=%sysfunc(DOPEN(&dirrf));
%if &psid %then %do;
%let today=%sysfunc(date(),mmddyy6.);
%let dirrc=%sysfunc(DCLOSE(&psid));
%let dirrc=%sysfunc(filename(dirrf));
%dir(directory=&directory, outdata=_dirtmp);
proc sort data=_dirtmp; by memname; run;
/* Read In the files until the stopsign */
DATA _tmp1;
length fileloc myinfile $ 300 line $ 2000;
set _dirtmp;
by memname;
line='';
if index(upcase(memname), &fextension) then do;
fileloc="&directory"||trim(left(memname));
infile dummy length=linelen /*filename=myinfile line=lnum*/ end=done filevar=fileloc;
do until(index(line, &stopsign) or done);
input @1 line $ varying2000. linelen;
if (index(trim(left(line)), '|') =1) then line=substr(trim(left(line)), 2);
if (index(reverse(trim(left(line))), '|') =1) then line=substr(trim(left(line)), 1, (length(trim(left(line)))-index(reverse(trim(left(line))), '|')));
output;
end;
end;
run;
/* Keep one observation per row, and concatenate the file headers */
/* into the file description.*/
data _tmp2;
set _tmp1;
by memname;
keep memname fDesBegRow fDesEndRow fHeaderBegRow fHeaderEndRow fParaBegRow fParaEndRow fLibBegRow
fLibEndrow fNeedBegRow fNeedEndrow fCreateBegRow fCreateEndrow fCommStartRow fCommEndRow;
retain fDesBegRow fDesEndRow fNeedBegRow fNeedEndrow fCreateBegRow fCreateEndRow fHeaderBegRow
fHeaderEndRow fParaBegRow fParaEndRow fCommStartRow fCommEndRow fLibBegRow fLibEndrow;
if first.memname then do;
fDesBegRow=0; fDesEndRow=0; fNeedBegRow=0; fNeedEndrow=0; fCreateBegRow=0; fCreateEndRow=0;
fHeaderBegRow=0; fHeaderEndRow=0; fParaBegRow=0; fParaEndRow=0; fCommStartRow=0; fCommEndRow=0;
fLibBegRow=0; fLibEndrow=0;
end;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and index(upcase(compbl(line)), 'HEADER')
then fHeaderBegRow =_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and index(upcase(compbl(line)), 'HEADER')
then fHeaderEndRow =_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and
(index(upcase(compbl(line)), 'DESCRIPTION') OR index(upcase(compbl(line)), 'PURPOSE'))
then fDesEndRow=_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and (index(upcase(compbl(line)), 'DESCRIPTION') OR index(upcase(compbl(line)), 'PURPOSE'))
then fDesBegRow=_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and index(upcase(line), 'PARAMETER')
then fParaBegRow =_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and index(upcase(line), 'PARAMETER')
then fParaEndRow =_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and index(upcase(line), 'LIBRARY')
then fLibBegRow=_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and index(upcase(line), 'LIBRARY')
then fLibEndrow=_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and index(upcase(compbl(line)), 'NEEDED')
then fNeedBegRow=_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and index(upcase(compbl(line)), 'NEEDED')
then fNeedEndRow=_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and
index(upcase(compbl(line)), 'CREATED')
then fCreateBegRow=_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and
index(upcase(compbl(line)), 'CREATED')
then fCreateEndRow=_n_-1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'START OF') and
(index(upcase(compbl(line)), 'COMMENT') OR index(upcase(compbl(line)), 'NOTE') OR index(upcase(compbl(line)), 'EXAMPLE'))
then fcommStartRow =_n_+1;
if index(line, '<') and index(line, '>') and index(line, '--') and
index(upcase(compbl(line)), 'END OF') and
(index(upcase(compbl(line)), 'COMMENT') OR index(upcase(compbl(line)), 'NOTE') OR index(upcase(compbl(line)), 'EXAMPLE'))
then fCommEndRow =_n_-1;
if last.memname;
run;
data _tmp3;
length line $4000.;
merge _tmp1 _tmp2;
by memname;
length fname $ 50 fHead fDes fPara fLib fNeed fCreate fComm $2000 dlm $100;
retain fHead fDes fPara fLib fNeed fCreate fComm;
fname=memname;
%if (%quote(&type) eq) or (%index(%quote(%upcase(&type)),%STR(XLS))) or
(%index(%quote(%upcase(&type)),%STR(EXCEL))) or (%index(%quote(%upcase(&type)),%STR(HTML))) %then %do;
dlm="
";
if first.memname then do; fhead=''; fDes='
'||trim(left(fhead)); fHead=compbl(trim(left(fHead)))||'